home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / FTP2UK23.ZIP / hhg21 < prev   
Text File  |  1992-04-10  |  9KB  |  267 lines

  1. #!/bin/sh
  2. # hhg - version 2.10
  3. # Use hhcp to get directory listings and files via FT-RELAY from specific
  4. #   site/directory combinations offering public access.
  5. #
  6. # Contents: 1. Installation and use
  7. #           2. Programme
  8. #           3. Installation data edited by users
  9. #           4. Site/BaseDirectory data edited by users
  10. #           5. History
  11. # H.Boothroyd, Warwick Business School, October 1991; corrected April 1992
  12. # bsrdp@warwick.ac.uk
  13. #
  14. # ==========================================================================
  15. # 1. Installation and use
  16. # =======================
  17. # a) This is a unix executable almost ready to run.
  18. #    Use a text editor on Section 3 to prepare  hhg  for use by you.
  19. #    Use a text editor on Section 4 to add data on sites/basedirectories.
  20. # b) In ordinary use (i.e. after Section 3 preparation) enter
  21. #       hhg
  22. #    for guidance on syntax and an up-to-date list of site names.
  23. # c) If an  hhg  request
  24. #    *  works, a suitably named file will arrive,
  25. #    *  fails, hhcp will send an automatic report to your mailbox,
  26. #    *  seems to have got lost, use commands of the form
  27. #               hhq -u YourUsername               hhlog | less
  28. #       to look for information about it.
  29. #
  30. # =========================================================================
  31. # 2. Script
  32. # =========
  33. # This is a shell script containing and running a gawk script.
  34.  
  35. # Test for presence of required unix utilities, if present add marker file
  36. # Not foolproof - older versions of gawk will probably not cope
  37. [ -f $HOME/.hhgok ] || {
  38.     for i in gawk hhalias hhstore hhcp
  39.     do
  40.         [ `which $i | wc -w` -ne 1 ] && {
  41.             echo This utility needs $i. See your system administrator.
  42.             exit 1 ;}
  43.     done
  44.     hhalias uk.ac.ft-relay ftb
  45.     sort -u -o $HOME/.hhalias $HOME/.hhalias
  46.     echo 'Required utilities for hhg are available' > $HOME/.hhgok ;}
  47.  
  48. # Send data, including this file, to gawk script for analysis and action
  49. { echo `hhstore -l ftb | wc -l` ; echo $* ; echo $0; cat $0 ;} | gawk '
  50.  
  51. # Start of gawk script
  52. # Detailed reference for awk/gawk programming
  53. #     "The AWK Programming Language", Aho,Kernighan,and Weinberg,
  54. #      Addison Wesley
  55.  
  56. # Record whether hhcp transfer parameters are present for ft-relay
  57. FNR==1 { if ( $0 ~ /^1$/ ) hhparam = "absent"
  58.                      else  hhparam = "present"
  59.          next
  60.        }
  61.  
  62. # Record the command parameters
  63. FNR==2 {
  64.     site=$1 ; subdir=$2 ; file=$3
  65.     if ( file=="-b" ) { swch="-b" ; file=$4 }
  66.     if ( subdir=="" || ( swch=="-b" && file=="" )) { help="yes"; next }
  67.     next
  68.     }
  69.  
  70. # Record pathname of hhg
  71. FNR==3 {
  72.     hhgpath=$1
  73.     next
  74.     }
  75.  
  76. # Process installation data
  77. /^# Installation data #$/,/^# Installation end #$/ {
  78.     msg0 = "Read " hhgpath " and install it as directed!"
  79.     msg1 = "Check installation section of hhg "
  80.     msg2 = ": e-mail address?"
  81.     msg3 = ": retain/delete?"
  82.     msg4 = ": plain/extended?"
  83.     if ( ictr == 3 ) { ictr++ ; next }
  84.     if ( ictr >  3 ) { print msg0 ; exit 1 }
  85.     getline ; ictr++
  86.         if (( NF > 1 )||( $0 !~ /@/ )) { print msg1 msg2 ; exit 1 }
  87.         # if (( $0 ~ /bsrdp/) && ( $0 ~ /warwick/ )) { print msg0 ; exit 1 }
  88.         address = $1
  89.     getline ; ictr++ ;
  90.         if (( NF > 1 )||(( $0 !~ /retain/ )&&( $0 !~ /delete/ )) ) {
  91.             print msg1 msg3 ; exit 1 }
  92.         hhaction = $1
  93.     getline ; ictr++ ;
  94.         if (( NF > 1 )||(( $0!~/plain/ )&&( $0 !~ /extended/ )) ) {
  95.             print msg1 msg4 ; exit 1 }
  96.         namestyle = $1
  97.     }
  98.  
  99. # Process site/directory data
  100. /^# Site data #$/,/^# Site end #$/ {
  101.     if ( sctr==0 ) { sctr++ ; getline }
  102.  
  103.     # Show help data
  104.     if ( help=="yes" ) {
  105.         if ( $0=="# Site end #" ) {
  106.             print "Example: hhg wuarchive . "
  107.             print "Example: hhg wuarchive arc-lbr -b fv138.zip"
  108.             exit 1
  109.             }
  110.         if ( helpctr==0 ) {
  111.             print  "Get file or directory list for " address
  112.             printf "         " namestyle " filenames, "
  113.             print              hhaction  " hhcp parameters"
  114.             print  "Own use: hhg site subdir"
  115.             print  "         hhg site subdir [-b] file"
  116.             print  "             |"
  117.             helpctr++
  118.             }
  119.         path=pathname($3,$4,"subdir","file")
  120.         printf("%+12s %-12s - get %s\n","",$1,path)
  121.         next
  122.         }
  123.  
  124.     # Site name not in data set
  125.     if ( $0=="# Site end #" ) {
  126.         print "Unknown site: " site
  127.         exit 1
  128.         }
  129.  
  130.     # Construct commands to call FT-RELAY, and execute
  131.     if ( $1==site ) {
  132.         "echo $HOME/hhgtmp1$$"   | getline tmp1
  133.         "echo $HOME/hhgtmp2$$"   | getline tmp2
  134.         # Instal  parameters for hhcp
  135.         if ( hhparam=="absent" ) {
  136.             print "hhstore ftb<<eof" > tmp1
  137.             print "anonymous" > tmp1 ; #transfer authorisation
  138.             print address     > tmp1 ; #transfer password
  139.             print ""          > tmp1 ; #account name
  140.             print ""          > tmp1 ; #account password
  141.             print ""          > tmp1 ; #file password
  142.             print ""          > tmp1 ; #output device type
  143.             print ""          > tmp1 ; #output device type qualifier
  144.             print ""          > tmp1 ; #mode of access
  145.             print "8"         > tmp1 ; #binary word size
  146.             print ""          > tmp1 ; #special options
  147.             print ""          > tmp1 ;
  148.             print "eof"       > tmp1 ;
  149.             system("sh " tmp1 " > " tmp2 )
  150.             system("rm " tmp1 )
  151.             }
  152.         # Construct hhcp command
  153.         path=pathname($3,$4,subdir,file)
  154.         loc=localname($1,subdir,file,namestyle)
  155.         if ( file=="" )
  156.             c=sprintf("hhcp -L ftb:\"%s::(D)%s\" %s\n",$2,path,loc)
  157.         else
  158.             c=sprintf("hhcp -L %s ftb:\"%s::%s\" %s\n",swch,$2,path,loc)
  159.         # Execute hhcp command
  160.         system(c)
  161.         # If required, de-install parameters for hhcp
  162.         if ( hhaction=="delete" ) {
  163.             system("hhstore -r ftb > " tmp2 )
  164.             system( " [ -f " tmp2 " ] && rm " tmp2 )
  165.             }
  166.         exit 0
  167.         }
  168.     }
  169.  
  170. END { exit 0 }
  171.  
  172. # Remote pathname constructor: returns full pathname at distant site
  173. function pathname( os, basedir, subdir, file,     path ) {
  174.     if ( os=="unix"   )  { path=basedir
  175.         if ( subdir!="." ) path=path "/" subdir
  176.         if ( file!="" )    path=path "/" file
  177.         }
  178.     if ( os=="tops20" )  { path=basedir
  179.         if ( subdir!="." ) path=path "." subdir
  180.         path=path ">"
  181.         if ( file!="" )    path=path file
  182.         }
  183.     if ( os=="vms"    )  { path=basedir
  184.         if ( subdir!="." ) path=path "." subdir
  185.         path=path "]"
  186.         if ( file!="" )    path=path file
  187.         }
  188.     if ( path=="" ) {
  189.         print "Unknown operating system: " os
  190.         exit 1
  191.         }
  192.     return path
  193.     }
  194.  
  195. # Local pathname constructor
  196. function localname( site, subdir, file, style,    local ) {
  197.     if (( file=="" )||( style=="extended" )) {
  198.         local=site
  199.         gsub("/",".",subdir)
  200.         if ( subdir!="." ) local=local "." subdir
  201.         if ( file!="" )    local=local "." file
  202.                       else local=local ".dir"
  203.         }
  204.     else local=file
  205.     return local
  206.     }
  207. '
  208. # End of gawk script
  209.  
  210. exit 0
  211. # End of shell script
  212.  
  213. # ==========================================================================
  214. # 3. Installation
  215. # ===============
  216.   Before first using this executable, use a text editor to edit the three
  217.   data lines in this section:
  218.     a) replace my email address with yours;
  219.     b) retain/delete hhcp transfer parameters after each call;
  220.     c) plain/extended versions of filenames - i.e. normal names or names
  221.        prefixed with site and directory info - directories are always
  222.        given extended names;
  223.   Preserve the # ... # head and tail lines exactly as they are.
  224.  
  225. # Installation data #
  226.   bsrdp@warwick.ac.uk
  227.   retain
  228.   extended
  229. # Installation end #
  230.  
  231. # ==========================================================================
  232. # 4. Remote Sites: Data and Base Directory Data
  233. # =============================================
  234.   Use a text editor to add/modify/delete data lines, following the
  235.   required format for each line:
  236.     a) your name for the combination of site and base directory (not yet
  237.        adapted to getting root directories),
  238.     b) the site address on Internet in mnemonic or numeric form,
  239.     c) the style of pathname at the site - unix, tops20, vms
  240.     d) a name stem for what you want to use as the base directory.
  241.   Items need not be aligned vertically.
  242.   Preserve the # ... # head and tail lines exactly as they are.
  243.  
  244. # Site data #
  245. simtel20   wsmr-simtel20.army.mil       tops20  pd1:<msdos
  246. simtel20u  wsmr-simtel20.army.mil       tops20  pd6:<unix-c
  247. oak        oak.oakland.edu              unix    /pub/msdos
  248. wuarchive  wuarchive.wustl.edu          unix    /mirrors/msdos
  249. garbo      garbo.uwasa.fi               unix    /pc
  250. garbou     128.214.87.1                 unix    /unix
  251. nic        nic.funet.fi                 unix    /pub/msdos
  252. somewhere  123.45.678.9                 vms     [directory
  253. # Site end #
  254.  
  255. # ==========================================================================
  256. # 5. History
  257. # ==========
  258.   Version 2.1
  259.     Added installation alternatives, checks, and vms sites.
  260.     Deleted requirement for separate installation of hhcp parameters.
  261.   Version 2.0
  262.     Rewrote to provide simple data structure.
  263.   Version 1.0
  264.     For files/directories from simtel20/unix sites.
  265.  
  266. # End of hhg, Version 2.1
  267.